package com.cn.ant.modules.score.service;

import com.cn.ant.common.persistence.Page;
import com.cn.ant.common.service.BaseService;
import com.cn.ant.modules.score.dao.LqMajorDao;
import com.cn.ant.modules.score.entity.LqMajor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 专业录取线Service
 * @author AntDream
 * @version 2015-08-28
 */
@Service
@Transactional(readOnly = true)
public class LqMajorService extends BaseService {

    @Autowired
	private LqMajorDao lqMajorDao;

	public LqMajor get(String id) {
		return lqMajorDao.get(id);
	}
	
	public List<LqMajor> findList(LqMajor lqMajor) {
		return lqMajorDao.findList(lqMajor);
	}
	
	public Page<LqMajor> findPage(Page<LqMajor> page, LqMajor lqMajor) {
	    lqMajor.setPage(page);
        page.setList(lqMajorDao.findList(lqMajor));
        return page;
	}

	public List<Map<String, String>> queryMajorCode(String majorCode, String klType, String batchLevel, String currYear, String maxYear) {
		Map<String, String> params = new HashMap<String, String>();
		params.put("majorCode", majorCode);
		params.put("klType", klType);
		params.put("batchLevel", batchLevel);
		params.put("currYear", currYear);
		params.put("maxYear", maxYear);
		return lqMajorDao.queryMajorCode(params);
	}

	public int queryLqMajorMaxYear(String majorCode, String klType, String batchLevel){
		Map<String, String> params = new HashMap<String, String>();
		params.put("majorCode", majorCode);
		params.put("klType", klType);
		params.put("batchLevel", batchLevel);
		return lqMajorDao.queryLqMajorMaxYear(params);
	}


	@Transactional(readOnly = false)
	public void save(LqMajor lqMajor) {
	    if (lqMajor.getIsNewRecord()) {
            lqMajor.preInsert();
            lqMajorDao.insert(lqMajor);
        } else {
            lqMajor.preUpdate();
            lqMajorDao.update(lqMajor);
        }
	}
	
	@Transactional(readOnly = false)
	public void delete(LqMajor lqMajor) {
		lqMajorDao.delete(lqMajor);
	}
	
}